package com.leyou.item.web;

import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.pojo.SpecGroup;
import com.leyou.item.pojo.SpecParam;
import com.leyou.item.service.SpecGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author: wangzibeng
 * Date: 2019/5/4 0004
 * Time: 14:14
 */
@RestController
@RequestMapping("spec")
public class SpecGroupController {
    @Autowired
    private SpecGroupService specGroupService;

    @GetMapping("groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> querySpecGroupById(@RequestParam("id") Long id) {
        return ResponseEntity.ok(specGroupService.querySpecGroupById(id));
    }

    @PutMapping("group")
    public ResponseEntity<Void> editGroup(@RequestBody SpecGroupDTO specGroupDTO) {
        specGroupService.editGroup(specGroupDTO);
        return ResponseEntity.status(HttpStatus.OK).build();
    }

    @DeleteMapping("group/{id}")
    public ResponseEntity<Void> deleteGroup(@PathVariable("id") Long id) {
        specGroupService.deleteGroup(id);
        return ResponseEntity.status(HttpStatus.OK).build();
    }

    @PostMapping("group")
    public ResponseEntity<Void> addGroup(@RequestBody SpecGroupDTO specGroupDTO) {
        specGroupService.addGroup(specGroupDTO);
        return ResponseEntity.status(HttpStatus.OK).build();
    }

    @GetMapping("of/category")
    public ResponseEntity<List<SpecGroupDTO>> querySpecsByCid3(@RequestParam("cid3") Long cid3) {
        return ResponseEntity.ok(specGroupService.querySpecsByCid3(cid3));
    }

}